package pubsub;

import com.rabbitmq.client.*;
import util.ConncetionUtil;

import java.io.IOException;

public class Consumer {
    public static final String QUEUENAME="lianjiezhe01";
    public static final String EXCHANGENAME="jhj";

    public static void main(String[] args) throws Exception{
        Connection connection = ConncetionUtil.getConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare(QUEUENAME,false,false,false,null);
        channel.queueBind(QUEUENAME,EXCHANGENAME,"");
        channel.basicConsume(QUEUENAME,true,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.err.println("从交换机上面获取的数据为"+new String(body));
            }
        });

    }
}
